package com.qq.BFMRSE.BF_MRSEController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.ContextLoader;

import com.qq.BFMRSE.Module.downloadTool;

@Controller
public class handlerDownLoadFile {
	@RequestMapping(value= "/downloadFile",method=RequestMethod.POST)
	public void handler(HttpServletRequest request,HttpServletResponse response){
		response.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/x-download");
	    Logger log=Logger.getLogger(handlerSearch.class);
		String userName=request.getParameter("userName");
		String downloads=request.getParameter("downLoads");
		String[] files=downloads.split(",");
		String tmpDir=ContextLoader.getCurrentWebApplicationContext().getServletContext().getRealPath("/")+"tmp";
		if(userName!=null&&!"".equals(userName)){
			downloadTool dt=new downloadTool(userName, files.length, tmpDir);
			dt.downloadFile(files, response);
			log.info("User:"+userName+" download files "+downloads);
		}
	}

}
